# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=libpaper
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.1.24
_suffix=+nmu4
pkgrel=1
pkgdesc="library for handling paper characteristics (mingw-w64)"
arch=('any')
url='http://packages.debian.org/unstable/source/libpaper'
license=('GPL-2')
makedepends=('gettext')
backup=("${MINGW_PREFIX:1}/etc/papersize")
source=("http://http.debian.net/debian/pool/main/libp/libpaper/${_realname}_${pkgver}${_suffix}.tar.gz")
sha256sums=('2491fce3f590d922d2d3070555df4425921b89c76a18e1c62e36336d6657526a')

prepare() {
  cd $srcdir/${_realname}-${pkgver}${_suffix}
}

build() {
  cd "$srcdir"/${_realname}-${pkgver}${_suffix}
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}
  ../${_realname}-${pkgver}${_suffix}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --sysconfdir=${MINGW_PREFIX}/etc \
    --sbindir=${MINGW_PREFIX}/bin \
    --enable-static \
    --enable-shared

  make
}

check() {
  cd "${srcdir}"/build-${CARCH}
  make check
}

package() {
  cd "${srcdir}"/build-${CARCH}
  make install DESTDIR="${pkgdir}"

  # add systemwide default papersize read by many office applications
  install -dm 755 $pkgdir${MINGW_PREFIX}/etc
  echo '# Simply write the paper name. See papersize(5) for possible values' > $pkgdir${MINGW_PREFIX}/etc/papersize

  # add libpaper.d directory other packages can use to store files
  install -dm 755 $pkgdir${MINGW_PREFIX}/etc/libpaper.d
  # add localisation
  pushd $srcdir/${_realname}-${pkgver}${_suffix}/debian/po
    for i in `ls *.po`; do
	install -dm 755 ${pkgdir}${MINGW_PREFIX}/share/locale/${i%.po}/LC_MESSAGES/;
	msgfmt $i -o ${pkgdir}${MINGW_PREFIX}/share/locale/${i%.po}/LC_MESSAGES/${pkgname}.mo;
    done
  popd
}
